<!--
 * @Descripttion: 
 * @Author: zhanyi
 * @Date: 2021-10-27 14:14:37
 * @FilePath: \wczd-mobile\src\pages\archives\archives.vue
-->
<template>
  <div class="safeNote">
    <div class="globalTitle">
      <div class="top-panel-cont">
        <image class="_image_icon" @click="back" src="@/static/wczd/back.png" alt=""></image>
        <div class="title">安全指标</div>
      </div>
      <div class="archives">
        <SearchBar placeholder="请输入关键字搜索" cancelButton="none" v-model="searchValue" :radius="5" />
      </div>
      <div class="addBtn" @click="handleAdd">新增</div>
    </div>
    <zPaging class="_sxwh_box" :default-page-size="10" :fixed='false' :height="'100%'" ref="paging" @query="queryList" v-model="jobManagerData" :delay='200' :refresher-end-bounce-enabled="false">
      <div class="_box_item" v-for="(item,index) in jobManagerData" :key="index">
        <div class="_title">
          <div class="_left">{{item.cutCompanyName}}</div>
          <!-- <div class="_right" :class="_isTextColor(item)">{{_isDanger(item)}}</div> -->
        </div>
        <div class="_center">
          <div class="_center_item">
            <div class="_left">指标项</div>
            <div class="_right">{{item.conditionDes}}</div>
          </div>
          <div v-if="item.inspectEndTime" class="_center_item">
            <div class="_left">整改期限</div>
            <div class="_right">{{ _inspectEndTime(item.inspectEndTime) }}</div>
          </div>
        </div>
        <div class="_footer" @click="_goInfo(item)">
          <div class="_left">
            详情
          </div>
          <div class="_right">
            <image class="_image_icon" src="@/static/wczd/more.png" alt="">
          </div>
        </div>
      </div>
    </zPaging>
  </div>
</template>

<script>
import SearchBar from "@/components/uni-search-bar/uni-search-bar.vue";
import { safetyCheckList } from "@/api/safeCheck";
import zPaging from '@/uni_modules/z-paging/components/z-paging/z-paging.vue'
import ZPagingMixin from '@/uni_modules/z-paging/components/z-paging/js/z-paging-mixin'
import customNomore from '@/pages/component/custom-nomore/custom-nomore.vue'
import moment from "moment";

export default {
  name: 'archives',
  components: { SearchBar, zPaging, customNomore },
  mixins: [ZPagingMixin],
  data () {
    return {
      searchValue: "",
      securityType: null,
      jobManagerData: []
    }
  },
  computed: {
    _inspectEndTime () {
      return function (inspectEndTime) {
        if (inspectEndTime) {
          return moment(inspectEndTime).format('YYYY-MM-DD')
        }
      }
    },
    // 计算作业类型
    _securityType: function () {
      return function (item) {
        let result = ''
        this.securityType.forEach(element => {
          if (element.dictValue == item) {
            result = element.dictLabel
          }
        });
        return result
      }
    },
    // 计算是否是隐患
    _isDanger: function () {
      return function (item) {
        return item.doState === '1' ? '已完成' : '待处理'
      }
    },
    // 计算颜色样式
    _isTextColor: function () {
      return function (item) {
        return item.doState === '1' ? '_GREEN' : '_RED'
      }
    },
  },
  watch: {
    searchValue () {
      this.queryList(1, 10)
    }
  },
  onShow () {
    this.queryList(1, 10)
    this.getDicts('security_type').then((response) => {
      this.securityType = response.data
    })
  },
  methods: {
    handleAdd () {
      uni.navigateTo({
        url: `/pages/safeNote/safeNote-edit`,
      })
    },
    // z-paging 查询方法
    queryList (pageNo, pageSize) {
      console.log(pageNo, pageSize);
      uni.showLoading({
        title: '加载中'
      });
      safetyCheckList({ cutCompanyName: this.searchValue, type: '2' }, { pageNum: pageNo, pageSize: pageSize }).then(res => {
        this.$refs.paging.complete(res.rows);
        uni.hideLoading();
      })
    },
    back () {
      uni.navigateBack({
        delta: 1
      });
    },
    _goInfo (item) {
      uni.navigateTo({
        url: `/pages/safeNote/safeNote-detail?id=${item.id}`,
      })
    }
  },
}
</script>

<style scoped lang="scss">
.safeNote {
  height: 100%;
}
.globalTitle {
  position: fixed;
  z-index: 99;
  .addBtn {
    position: absolute;
    right: 40upx;
    top: 140upx;
    padding: 6upx 16upx;
    background-color: #ffb500;
    border-radius: 10upx;
    color: #fff;
  }
}
._sxwh_box {
  padding-top: 195px;
  height: 100%;
}
.title {
  padding-left: 0;
}
.top-panel-cont {
  display: flex;
  align-items: center;
  image {
    margin-left: 30upx;
    margin-top: 120upx;
    width: 56upx;
    height: 56upx;
  }
  div {
    font-size: 40upx;
    font-weight: bold;
  }
}
</style>
